package io.renren.modules.task.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.task.dao.MtCcEquipmentRunInfoDao;
import io.renren.modules.task.entity.MtCcEquipmentRunInfoEntity;
import io.renren.modules.task.model.MtCcEquipmentRunInfoEntityVo;
import io.renren.modules.task.service.MtCcEquipmentRunInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static io.renren.common.utils.DateUtils.getTodayTime;


@Service("mtCcEquipmentRunInfoService")
public class MtCcEquipmentRunInfoServiceImpl extends ServiceImpl<MtCcEquipmentRunInfoDao, MtCcEquipmentRunInfoEntity> implements MtCcEquipmentRunInfoService {

    @Autowired
    private MtCcEquipmentRunInfoDao mtCcEquipmentRunInfoDao;

    @Override
    public Integer countByTasktype(Integer type) {

        QueryWrapper<MtCcEquipmentRunInfoEntity> mt = new QueryWrapper<>();
        mt.eq("task_type",type);
        mt.between("create_time",getTodayTime(0),getTodayTime(1));

        return baseMapper.selectCount(mt);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MtCcEquipmentRunInfoEntity> page = this.page(
                new Query<MtCcEquipmentRunInfoEntity>().getPage(params),
                new QueryWrapper<MtCcEquipmentRunInfoEntity>()
        );

        return new PageUtils(page);
    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void update(MtCcEquipmentRunInfoEntity mtCcEquipmentRunInfoEntity) {
//        this.updateById(mtCcEquipmentRunInfoEntity);
//    }

    @Override
    public List<MtCcEquipmentRunInfoEntity> selectRunInfoByCreatTimeAsc() {
        return baseMapper.selectList(new QueryWrapper<MtCcEquipmentRunInfoEntity>().orderByAsc("create_time"));
    }

    @Override
    public PageUtils selectListOne(Map<String, Object> params) {
        Page<MtCcEquipmentRunInfoEntityVo> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<MtCcEquipmentRunInfoEntityVo> list = mtCcEquipmentRunInfoDao.selectListOne(page,params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    @Override
    public List<MtCcEquipmentRunInfoEntityVo> showWare(Map<String, Object> params) {
        return mtCcEquipmentRunInfoDao.showWare(params);
    }

    @Override
    public PageUtils listOne(Map<String, Object> params) {
        Page<MtCcEquipmentRunInfoEntityVo> page = new Page<>();
        page.setCurrent(Integer.valueOf(params.get("page").toString()));
        page.setSize(Integer.valueOf(params.get("limit").toString()));
        List<MtCcEquipmentRunInfoEntityVo> list = mtCcEquipmentRunInfoDao.listOne(page,params);
        page.setRecords(list);
        return new PageUtils(page);
    }


}